package com.simple.util.base.extend.zip;

import net.lingala.zip4j.core.ZipFile;

/**
 * @program: simple_tools
 * @description: ZIP解壓工具
 * @author: ChenWenLong
 * @create: 2020-01-07 16:52
 **/
public class ZipUtil {

    /**
     * 功能描述:
     * 〈解压zip文件〉
     *
     * @params : [zipFilePath, targetPath]
     * @return : void
     * @author : cwl
     * @date : 2020/1/7 16:52
     */
    public static void unzip(String zipFilePath,String targetPath) throws Exception{
        ZipFile zipFile = new ZipFile(zipFilePath);
        zipFile.extractAll(targetPath);
    }

    /**
     * 功能描述:
     * 〈解压zip文件（带密码）〉
     *
     * @params : [zipFilePath, password, targetPath]
     * @return : void
     * @author : cwl
     * @date : 2020/1/7 16:54
     */
    public static void unzip(String zipFilePath,String password,String targetPath) throws Exception{
        ZipFile zipFile = new ZipFile(zipFilePath);
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        zipFile.extractAll(targetPath);
    }

}
